package com.wsjzzcbq.qianyuan.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;

/**
 * CookieUtil
 *
 * @author wsjz
 * @date 2021/10/26
 */
public class CookieUtils {

    /**
     * 获取cookie值
     * @param name
     * @return
     */
    public static String getValyeByName(String name) {
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (sra.getRequest().getCookies() != null) {
            for (Cookie cookie : sra.getRequest().getCookies()) {
                if (name.equals(cookie.getName())) {
                    return cookie.getValue();
                }
            }
        }

        return "";
    }
}
